package com.c.ctgproject.adapter.doorkeeper

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.entity.doorkeeper.DoorkeeperMaterialOutEntity
import com.c.ctgproject.utils.handlerNull

/**
 *作者:LiBW
 *创建日期: 2020/9/14
 *描述:门卫 物料出场 列表
 */
class DoorkeeperMaterialOutAdapter(private val context: Context, private val mList: List<DoorkeeperMaterialOutEntity.DataBean.ListBean>, private val callback: Callback) : RecyclerView.Adapter<DoorkeeperMaterialOutAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_doorkeeper_material_out_list, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = mList[position]
        holder.mOrderID.text = data.materialSalesNo.handlerNull()
        holder.mSellerNameTV.text = data.userName.handlerNull()
        holder.mCarPlateTV.text = data.truckPlate.handlerNull()
        holder.mMaterialNameTV.text = data.materialName.handlerNull()
        holder.mWeightTV.text = data.suttleWeight.handlerNull()
        holder.mNumberTV.text = data.loadingNumber.handlerNull()
        holder.mConfirmBTN.setOnClickListener {
            callback.materialOutConfirm(data.truckTrafficId, data.materialSalesOrderId)
        }
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val mOrderID: TextView = itemView.findViewById(R.id.mOrderID)
        val mSellerNameTV: TextView = itemView.findViewById(R.id.mSellerNameTV)
        val mConfirmBTN: Button = itemView.findViewById(R.id.mConfirmBTN)
        val mCarPlateTV: TextView = itemView.findViewById(R.id.mOrderIdTV)
        val mMaterialNameTV: TextView = itemView.findViewById(R.id.mMaterialNameTV)
        val mWeightTV: TextView = itemView.findViewById(R.id.mWeightTV)
        val mNumberTV: TextView = itemView.findViewById(R.id.mNumberTV)
    }

    interface Callback {
        fun materialOutConfirm(truckTrafficId: Int, materialSalesOrderId: Int)
    }

}